#pragma once
class Tank;  // 前向声明

#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include "Map.hpp"
#include <memory>
#include <vector>

class Game {
public:
    Game();
    static sf::Vector2u getDesiredWindowSize();
    void run();
    void playTurnSound();   // 播放转向音效
    void setGameOver(bool gameOver) { mGameOver = gameOver; }  // 设置游戏结束状态
    const Map& getMap() const { return mMap; }  // 获取地图对象

private:
    void processEvents();
    void update(sf::Time deltaTime);
    void render();
    void handleCollisions();
    void spawnEnemy();
    void renderInstructions();
    void renderGameStatus();
    void checkGameOver();
    void reset();  // 重置游戏

    sf::RenderWindow mWindow;
    std::unique_ptr<Tank> mPlayer;
    std::vector<std::unique_ptr<Tank>> mEnemies;
    Map mMap;
    
    sf::Font mFont;
    sf::Text mInstructionsText;
    sf::Text mScoreText;
    sf::Text mGameOverText;
    
    // 音频相关
    sf::Music mBackgroundMusic;
    sf::SoundBuffer mTurnSoundBuffer;  // 转向音效缓冲
    sf::Sound mTurnSound;  // 转向音效
    
    void loadAudio();  // 加载音频资源
    
    static constexpr float SPAWN_INTERVAL = 5.f;  // 敌人生成间隔（秒）
    sf::Clock mSpawnClock;
    
    bool mIsMovingUp = false;
    bool mIsMovingDown = false;
    bool mIsMovingLeft = false;
    bool mIsMovingRight = false;
    bool mIsShooting = false;
    
    int mScore = 0;
    bool mGameOver = false;
    static constexpr int POINTS_PER_KILL = 100;  // 击杀一个敌人得分
};